import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;


/**
 * @Author Stringzhua
 * @Date 2024/10/30 15:55
 * description:都是创建ThreadPoolExecutor对象
 */
public class ThreadPool05 {
    public static void main(String[] args) {
        /**
         * 固定数量的线程池
         * new ThreadPoolExecutor(nThreads, nThreads,
         * 0L, TimeUnit.MILLISECONDS,
         * new LinkedBlockingQueue<Runnable>());
         * 运行结果:
         * pool-1-thread-2-->5fae2052-293e-472f-b6ba-2f69e0883136
         * pool-1-thread-2-->fb7ac013-3594-4e7f-970a-dc6892a44162
         * pool-1-thread-3-->bf1e5e54-7cec-4506-b410-adf2d4047e4b
         * pool-1-thread-5-->3e996f0d-0f46-4566-af29-02a00e95e610
         * pool-1-thread-4-->1feebdfe-4449-4ecc-b965-9f632229f94c
         * pool-1-thread-1-->dc16863d-3698-4b3c-bacc-d7fac4d7ded9
         * pool-1-thread-2-->eef2fc70-278a-4ae1-9862-4fe5b8a2ad73
         */
//        ExecutorService threadPool = Executors.newFixedThreadPool(5);

        /**
         * 动态数量线程池【高速的工作队列】
         * new ThreadPoolExecutor(0, Integer.MAX_VALUE,
         * 60L, TimeUnit.SECONDS,
         * new SynchronousQueue<Runnable>());
         * 运行结果：
         * pool-1-thread-21401-->0dfac5a5-ee43-49ea-b430-7c8a9e4ea5f0
         * pool-1-thread-21402-->7a158d82-9051-49bd-87fe-6f31488856fe
         * pool-1-thread-21400-->a63f2f5e-452e-43d4-bf6b-1415eb019323
         * pool-1-thread-21399-->3817dc2b-ba5b-4f2a-a2c5-676c1a6e39db
         * pool-1-thread-21398-->47679b60-16c0-464d-9ae9-377676ad3b2a
         * pool-1-thread-21397-->e933c683-5e0d-483f-b296-a6ac1261239f
         * pool-1-thread-12921-->e574c4d2-068a-4d50-8312-b8e998167498
         */
//        ExecutorService threadPool = Executors.newCachedThreadPool();

        /**
         * 单独线程的线程池
         * new ThreadPoolExecutor(1, 1,
         * 0L, TimeUnit.MILLISECONDS,
         * new LinkedBlockingQueue<Runnable>()));
         * 运行结果:
         * pool-1-thread-1-->6454e147-cb9a-4d7c-b351-f5e29a17cedb
         * pool-1-thread-1-->80248086-8bac-4ef6-ab36-ed79595b98ca
         * pool-1-thread-1-->9fb14c03-0995-4598-bc6e-a18e7292d2af
         * pool-1-thread-1-->932d0a6a-fdcc-4c20-ac60-410ef59ef1fa
         * pool-1-thread-1-->b032f31a-0529-44b4-817f-d6f11a0c8d5d
         * pool-1-thread-1-->d1fbeaa2-ee0d-4b83-95b9-fc62d220b331
         */
        ExecutorService threadPool = Executors.newSingleThreadExecutor();

        for (int i = 0; i < 100000; i++) {
            threadPool.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getName() + "-->" + UUID.randomUUID());
                }
            });
        }
        threadPool.shutdown();
    }
}
